/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "project_has_user", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ProjectHasUser.findAll", query = "SELECT p FROM ProjectHasUser p"),
    @NamedQuery(name = "ProjectHasUser.findByProjectPrjId", query = "SELECT p FROM ProjectHasUser p WHERE p.projectHasUserPK.projectPrjId = :projectPrjId"),
    @NamedQuery(name = "ProjectHasUser.findByUserUserId", query = "SELECT p FROM ProjectHasUser p WHERE p.projectHasUserPK.userUserId = :userUserId"),
    @NamedQuery(name = "ProjectHasUser.findByLastUpdate", query = "SELECT p FROM ProjectHasUser p WHERE p.lastUpdate = :lastUpdate")})
public class ProjectHasUser implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProjectHasUserPK projectHasUserPK;
    @Basic(optional = false)
    @Column(name = "last_update")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdate;
    @JoinColumn(name = "user_user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "project_prj_id", referencedColumnName = "prj_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Project project;

    public ProjectHasUser() {
    }

    public ProjectHasUser(ProjectHasUserPK projectHasUserPK) {
        this.projectHasUserPK = projectHasUserPK;
    }

    public ProjectHasUser(ProjectHasUserPK projectHasUserPK, Date lastUpdate) {
        this.projectHasUserPK = projectHasUserPK;
        this.lastUpdate = lastUpdate;
    }

    public ProjectHasUser(int projectPrjId, int userUserId) {
        this.projectHasUserPK = new ProjectHasUserPK(projectPrjId, userUserId);
    }

    public ProjectHasUserPK getProjectHasUserPK() {
        return projectHasUserPK;
    }

    public void setProjectHasUserPK(ProjectHasUserPK projectHasUserPK) {
        this.projectHasUserPK = projectHasUserPK;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (projectHasUserPK != null ? projectHasUserPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProjectHasUser)) {
            return false;
        }
        ProjectHasUser other = (ProjectHasUser) object;
        if ((this.projectHasUserPK == null && other.projectHasUserPK != null) || (this.projectHasUserPK != null && !this.projectHasUserPK.equals(other.projectHasUserPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.ProjectHasUser[ projectHasUserPK=" + projectHasUserPK + " ]";
    }
    
}
